package org.yefei.homeworkday26;

import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Company implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/*
	 * 公司有公司名称，注册地址，电话，经营范围等属性（动态输入），公司有很多员工（用List存储，作为公司的一部分），员工有姓名，年龄，性别，职务，薪水、
	 * 工号等属性，公司有招聘员工（要求工号不能重复），有输出员工信息，以及辞退员工，和统计公司人数的方法
	 * 用oo的思想模拟，同时序列化公司的全部信息（包括员工）。下次启动能获得上次的信息。
	 */
	private String name;
	private String address;
	private String phoneNum;
	private String range;
	List<Staff> list = new LinkedList<>();

	public Company() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	public String getRange() {
		return range;
	}

	public void setRange(String range) {
		this.range = range;
	}

	public Company(String name, String address, String phoneNum, String range) {
		this.name = name;
		this.address = address;
		this.phoneNum = phoneNum;
		this.range = range;
	}

	/*
	 * { list.add(new Staff("张量", 31, "男", "总裁", 30, "001")); list.add(new
	 * Staff("王芒", 30, "男", "总经理", 20, "002")); list.add(new Staff("李莉", 29, "女",
	 * "主管", 10, "003")); list.add(new Staff("赵斯", 27, "男", "HR", 5, "004"));
	 * list.add(new Staff("孙亚", 21, "女", "员工", 1, "005")); }
	 */

	// 公司信息动态输入
	public void showCompany() {
		System.out.print("欢迎进入" + name + "有限公司！");
		System.out.print("本公司地址是：" + address + ",");
		System.out.print("电话：" + phoneNum + ",");
		System.out.println("经营范围：" + range);
	}

	// 招聘新员工
	public boolean addNewStaff(Staff f) {
		if (!(list.contains(f))) {
			list.add(f);
			System.out.println("欢迎新人加入公司！");
			return true;
		}
		System.out.println("加入公司失败！");
		return false;
	}

	// 输出员工信息
	public void printStaff() {
		for (Object object : list) {
			Staff ss = (Staff) object;
			System.out.println(ss);
		}
	}

	// 辞退员工
	public boolean fireStaff(String num) {
		Iterator<Staff> it = list.iterator();
		while (it.hasNext()) {
			Staff ss = (Staff) it.next();
			if (num.equals(ss.getwNum())) {
				list.remove(ss);
				System.out.println("该员工已被删除！");
				return true;
			}
		}
		System.out.println("删除失败！");
		return false;
	}

	// 统计公司人数
	public void cal() {
		System.out.println("公司有：" + list.size() + "人");
	}

	@Override
	public String toString() {
		return "Company [name=" + name + ", address=" + address + ", phoneNum=" + phoneNum + ", range=" + range
				+ ", list=" + list + "]";
	}

}
